package monitor.mbean;

import monitor.connector.Connector;
import weblogic.management.runtime.ExecuteThread;

public class ThreadPoolRuntimeMBean {

	public static Integer getCompletedRequestCount() {
		return (Integer)Connector.getThreadPoolRuntimeMBeanAttribute("CompletedRequestCount");
	}
	public static Integer getExecuteThreadIdleCount() {
		return (Integer)Connector.getThreadPoolRuntimeMBeanAttribute("ExecuteThreadIdleCount");
	}
	public static String getExecuteThreads() {

		ExecuteThread[] thread = (ExecuteThread[])Connector.getThreadPoolRuntimeMBeanAttribute("ExecuteThreads");

		StringBuffer rtnString = new StringBuffer();
		
		for(int i=0; i < thread.length; i++){
			rtnString.append("\n[").append(thread[i].isStandby()? "STAND BY":"ACTIVE").append("] ExecuteThread: '").append(i).append("' for queue: 'weblogic.kernel.Default (self-tuning)'");
			rtnString.append("\n       current request : ").append(thread[i].getCurrentRequest());
			rtnString.append("\n       user            : ").append(thread[i].getUser());
			rtnString.append("\n       stuck thread    : ").append(thread[i].isStuck());
			rtnString.append("\n       WorkManager     : ").append(thread[i].getWorkManagerName());
		}
		
		return rtnString.toString();
	}
	public static Integer getExecuteThreadTotalCount() {
		return (Integer)Connector.getThreadPoolRuntimeMBeanAttribute("ExecuteThreadTotalCount");
	}
	public static String getHealthState() {
		return (String)Connector.getThreadPoolRuntimeMBeanAttribute("HealthState");
	}
	public static Integer getHoggingThreadCount() {
		return (Integer)Connector.getThreadPoolRuntimeMBeanAttribute("HoggingThreadCount");
	}
	public static Integer getMinThreadsConstraintsCompleted() {
		return (Integer)Connector.getThreadPoolRuntimeMBeanAttribute("MinThreadsConstraintsCompleted");
	}
	public static Integer getMinThreadsConstraintsPending() {
		return (Integer)Connector.getThreadPoolRuntimeMBeanAttribute("MinThreadsConstraintsPending");
	}
	public static Integer getName() {
		return (Integer)Connector.getThreadPoolRuntimeMBeanAttribute("Name");
	}
	public static Integer getParent() {
		return (Integer)Connector.getThreadPoolRuntimeMBeanAttribute("Parent");
	}
	public static Integer getPendingUserRequestCount() {
		return (Integer)Connector.getThreadPoolRuntimeMBeanAttribute("PendingUserRequestCount");
	}
	public static Integer getQueueLength() {
		return (Integer)Connector.getThreadPoolRuntimeMBeanAttribute("QueueLength");
	}
	public static Integer getSharedCapacityForWorkManagers() {
		return (Integer)Connector.getThreadPoolRuntimeMBeanAttribute("SharedCapacityForWorkManagers");
	}
	public static Integer getStandbyThreadCount() {
		return (Integer)Connector.getThreadPoolRuntimeMBeanAttribute("StandbyThreadCount");
	}
	public static Integer getSuspended() {
		return (Integer)Connector.getThreadPoolRuntimeMBeanAttribute("Suspended");
	}
	public static Integer getThroughput() {
		return (Integer)Connector.getThreadPoolRuntimeMBeanAttribute("Throughput");
	}
	public static Integer getType() {
		return (Integer)Connector.getThreadPoolRuntimeMBeanAttribute("Type");
	}
}